package com.zhoujing.cinema.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhoujing.cinema.dao.UserDao;
import com.zhoujing.cinema.entity.*;
import com.zhoujing.cinema.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ：ywj
 * @date ：Created in 2020/3/17 11:37
 * @description：
 * @modified By：
 * @version: $
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {
    @Autowired
    public UserDao userDao;
    @Override
    public User findUserByName(String username) {
        return userDao.selectUserByName(username);
    }

    @Override
    public void addUser(User user) {
        userDao.insertUser(user);
    }

    @Override
    public User findUserById(Integer userId) {
        return userDao.selectUserById(userId);
    }

    @Override
    public Boolean verifyUsername(String username) {

        if(userDao.selectUserByName(username) == null){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void modifyUserInfo(User user) {
        userDao.updateUserInfo(user);
    }

    @Override
    public PageInfo<User> selectAllUser(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> jobs=userDao.selectAllUser();
        PageInfo<User> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public PageInfo<User> searchUser(String username, Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> jobs=userDao.searchUser(username);
        PageInfo<User> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public void changeRole(User user) {
        userDao.changeRole(user);
    }

    @Override
    public PageInfo<Type> selectAllType(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Type> jobs=userDao.selectAllType();
        PageInfo<Type> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public void insertType(Type type) {
        userDao.insertType(type);
    }

    @Override
    public void updateType(Type type) {
        userDao.updateType(type);
    }

    @Override
    public PageInfo<Country> selectAllArea(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Country> jobs=userDao.selectAllArea();
        PageInfo<Country> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public void insertArea(Country country) {
        userDao.insertArea(country);
    }

    @Override
    public void updateArea(Country country) {
        userDao.updateArea(country);
    }

    @Override
    public PageInfo<Year> selectAllYear(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Year> jobs=userDao.selectAllYear();
        PageInfo<Year> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public void insertYear(Year year) {
        userDao.insertYear(year);
    }

    @Override
    public void updateYear(Year year) {
        userDao.updateYear(year);
    }

    @Override
    public List<Movie> selectAllMovies() {
        return userDao.selectAllMovies();
    }

    @Override
    public PageInfo<Banner> selectAllBanner(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Banner> jobs=userDao.selectAllBanner();
        PageInfo<Banner> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public void addBanner(Banner banner) {
        userDao.addBanner(banner);
    }

    @Override
    public void updateBanner(Banner banner) {
        userDao.updateBanner(banner);
    }

    @Override
    public void updateBanner1(Banner banner) {
        userDao.updateBanner1(banner);
    }

    @Override
    public void changeRole1(Banner banner) {
        userDao.changeRole1(banner);
    }

}
